package com.ruoyi.archive.service.impl;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.archive.domain.SRetiredCadre;
import com.ruoyi.archive.domain.SSoldierBaseInfo;
import com.ruoyi.archive.service.ISTransferredCadresService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.archive.mapper.SRetiredNoMilitaryMapper;
import com.ruoyi.archive.domain.SRetiredNoMilitary;
import com.ruoyi.archive.service.ISRetiredNoMilitaryService;

/**
 * 军队无军籍离休退休退职职工信息Service业务层处理
 *
 * @author Allen
 * @date 2021-09-29
 */
@Service
public class SRetiredNoMilitaryServiceImpl extends ServiceImpl<SRetiredNoMilitaryMapper, SRetiredNoMilitary> implements ISRetiredNoMilitaryService {
    @Autowired
    private SRetiredNoMilitaryMapper sRetiredNoMilitaryMapper;
    @Autowired
    private ISTransferredCadresService transferredCadresService;

    /**
     * 查询军队无军籍离休退休退职职工信息
     *
     * @param id
     *         军队无军籍离休退休退职职工信息主键
     *
     * @return 军队无军籍离休退休退职职工信息
     */
    @Override
    public SRetiredNoMilitary selectSRetiredNoMilitaryById(Long id) {
        return sRetiredNoMilitaryMapper.selectSRetiredNoMilitaryById(id);
    }

    /**
     * 查询军队无军籍离休退休退职职工信息列表
     *
     * @param sRetiredNoMilitary
     *         军队无军籍离休退休退职职工信息
     *
     * @return 军队无军籍离休退休退职职工信息
     */
    @Override
    public List<SRetiredNoMilitary> selectSRetiredNoMilitaryList(SRetiredNoMilitary sRetiredNoMilitary) {
        List<SRetiredNoMilitary> retiredNoMilitaryList = sRetiredNoMilitaryMapper.selectSRetiredNoMilitaryList(sRetiredNoMilitary);
        if (CollectionUtil.isNotEmpty(retiredNoMilitaryList)) {
            List<Long> soldierIdList = retiredNoMilitaryList.stream().map(SRetiredNoMilitary::getSoldierId).collect(Collectors.toList());
            Map<Long, SSoldierBaseInfo> baseInfoMap = transferredCadresService.getSoldierBaseInfoMap(soldierIdList);
            retiredNoMilitaryList.stream().forEach(x -> x.setSoldierName(baseInfoMap.get(x.getSoldierId()).getName()));
            retiredNoMilitaryList.stream().forEach(x -> x.setIdCard(baseInfoMap.get(x.getSoldierId()).getIdCard()));
        }
        return retiredNoMilitaryList;
    }

    /**
     * 新增军队无军籍离休退休退职职工信息
     *
     * @param sRetiredNoMilitary
     *         军队无军籍离休退休退职职工信息
     *
     * @return 结果
     */
    @Override
    public int insertSRetiredNoMilitary(SRetiredNoMilitary sRetiredNoMilitary) {
        if (sRetiredNoMilitary != null) {
            return sRetiredNoMilitaryMapper.insertSRetiredNoMilitary(sRetiredNoMilitary);
        }
        return 0;
    }

    /**
     * 修改军队无军籍离休退休退职职工信息
     *
     * @param sRetiredNoMilitary
     *         军队无军籍离休退休退职职工信息
     *
     * @return 结果
     */
    @Override
    public int updateSRetiredNoMilitary(SRetiredNoMilitary sRetiredNoMilitary) {
        return sRetiredNoMilitaryMapper.updateSRetiredNoMilitary(sRetiredNoMilitary);
    }

    /**
     * 批量删除军队无军籍离休退休退职职工信息
     *
     * @param ids
     *         需要删除的军队无军籍离休退休退职职工信息主键
     *
     * @return 结果
     */
    @Override
    public int deleteSRetiredNoMilitaryByIds(Long[] ids) {
        return sRetiredNoMilitaryMapper.deleteSRetiredNoMilitaryByIds(ids);
    }

    /**
     * 删除军队无军籍离休退休退职职工信息信息
     *
     * @param id
     *         军队无军籍离休退休退职职工信息主键
     *
     * @return 结果
     */
    @Override
    public int deleteSRetiredNoMilitaryById(Long id) {
        return sRetiredNoMilitaryMapper.deleteSRetiredNoMilitaryById(id);
    }
}
